--[[
 -- *名称:SortCard
 -- *描述:牌数量排序辅助
 -- *版权:Copyright © 2016-2018 深圳市三只小熊科技有限公司 版权所有
 -- *作者:Administrator
 -- *创建日期:2017-11-07
 -- *修改日期:2017-11-07
 ]]
local SortCard = pokercore.class();

--设置元表
local mt = {};

mt.__tostring = function (t)
   return "card->(" ..(t.card and tostring(t.card) or "nil") .. ") " ..",result->".. (t.result and tostring(t.result) or  nil) .. ",";
end


---
 -- [ctor 默认类的构造方法]
 -- @DateTime 2017-09-20
 -- @param     [description]
 -- @return    [description]
 --
function SortCard:ctor(card,result)
	self.card = card ;
	self.result = result ;
	local meta = getmetatable(self) or {};
    table.merge(meta,mt)
    setmetatable(self,meta)
end

--[[
 -- [compareTo 数量多的排前面 比如 344442 --> 444432]
 -- @DateTime 2017-11-07
 -- @param    o [description]
 -- @return    [description]
 ]]
function SortCard:compareTo(o)
	local card = self.card ;
	local result = self.result ;
	----print("firstValue->",result:getSortFirstValue() or "nil");
	if (card:getValue() == result:getSortFirstValue()) and (o.card:getValue() == result:getSortFirstValue()) then
		if (self:getCount() > o:getCount()) then
			return -1;
		elseif (self:getCount() < o:getCount()) then
			return 1;
		else 
			return card:compareWithShapeTo(o.card);
		end
	elseif (card:getValue() == result:getSortFirstValue()) then
		return -1;
	elseif (o.card:getValue() == result:getSortFirstValue()) then
		return 1;
	else 
		if (self:getCount() > o:getCount()) then
			return -1;
		elseif (self:getCount() < o:getCount()) then
			return 1;
		else 
		--	--print("SortCard:compareTo")
			return card:compareWithShapeTo(o.card);
		end
	end
end


function SortCard:getCount()
	return self.result:getAllValueCounter():getValueCount(self.card:getValue());
end


function SortCard:getCard()
    return self.card ;
end

function SortCard:setCard(card)
	self.card = card ;
end

---
 -- [dtor 默认类的销毁方法]
 -- @DateTime 2017-09-20
 -- @param     [description]
 -- @return    [description]
 --
function SortCard:dtor(...)
  
end

return SortCard;

